home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / LAYOUTWI.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  167 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.5  $
  6. //
  7. // Definition of classes TLayoutMetrics & TLayoutWindow
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_LAYOUTWI_H)
  10. #define OWL_LAYOUTWI_H
  11.  
  12. #if !defined(OWL_WINDOW_H)
  13. # include <owl/window.h>
  14. #endif
  15. #if !defined(OWL_LAYOUTCO_H)
  16. # include <owl/layoutco.h>
  17. #endif
  18.  
  19. #if defined(BI_NAMESPACE)
  20. namespace OWL {
  21. #endif
  22.  
  23. // Generic definitions/compiler options (eg. alignment) preceeding the 
  24. // definition of classes
  25. #include <services/preclass.h>
  26.  
  27. //
  28. // class TLayoutMetrics
  29. // ~~~~~ ~~~~~~~~~~~~~~
  30. // When specifying the layout metrics for a window, four layout constraints
  31. // are needed.
  32. //
  33. class _OWLCLASS TLayoutMetrics {
  34.   public:
  35.     TEdgeConstraint         X;      // Horz1 can be lmLeft, lmCenter, lmRight
  36.     TEdgeConstraint         Y;      // Vert1 can be lmTop, lmCenter, lmBottom
  37.     TEdgeOrWidthConstraint  Width;  // Horz2 can be lmWidth, lmCenter, lmRight
  38.     TEdgeOrHeightConstraint Height; // Vert2 can be lmHeight, lmCenter, lmBottom
  39.  
  40.     // Defaults each co: RelWin=0, MyEdge=(1st from above), Relationship=AsIs
  41.     //
  42.     TLayoutMetrics();
  43.   
  44.     void SetMeasurementUnits(TMeasurementUnits units);
  45. };
  46.  
  47. //
  48. // Private structs used by TLayoutWindow
  49. //
  50. struct TChildMetrics;
  51. struct TConstraint;
  52. struct TVariable;
  53.  
  54. //
  55. // class TLayoutWindow
  56. // ~~~~~ ~~~~~~~~~~~~~
  57. // When specifying the layout metrics for a window, there are several options:
  58. // e.g. in the horizontal direction,
  59. //
  60. //  Two Edge Constraints in X and Width
  61. //   1. left edge and right edge
  62. //   2. center edge and right edge
  63. //   3. left edge and center edge
  64. //
  65. //  Edge Constraint and Size constraint in X and Width
  66. //   4. left edge and size
  67. //   5. right edge and size
  68. //   6. center edge and size
  69. //
  70. // The same holds true in the vertical direction for Y and Height
  71. //
  72. // It is also possible to specify "lmAsIs" in which case we use the windows
  73. // current value
  74. //
  75. // Specifying "lmAbsolute" means that we will use whatever is in data member
  76. // "Value"
  77. //
  78. // We just name the fields "X" and "Width" and "Y" and "Height",
  79. // although its okay to place a right or center edge constraint in the
  80. // "Width" field and its also okay to place a right edge constraint in
  81. // the "X" field (i.e. option #3)
  82. //
  83. // However, it's NOT okay to place a width constraint in the "X" or
  84. // "Height" fields or a height constraint in the "Y" or "Width" fields.
  85. //
  86. class _OWLCLASS TLayoutWindow : virtual public TWindow {
  87.   public:
  88.     TLayoutWindow(TWindow*        parent,
  89.                   const char far* title = 0,
  90.                   TModule*        module = 0);
  91.  
  92.    ~TLayoutWindow();
  93.  
  94.     // Causes the receiver to size/position its children according to the
  95.     // specified layout metrics
  96.     //
  97.     // If you change the layout metrics for a child window call Layout()
  98.     // to have the changes take effect
  99.     //
  100.     virtual void    Layout();
  101.  
  102.     void            SetChildLayoutMetrics(TWindow& child, TLayoutMetrics& metrics);
  103.     bool            GetChildLayoutMetrics(TWindow& child, TLayoutMetrics& metrics);
  104.     bool            RemoveChildLayoutMetrics(TWindow& child);
  105.  
  106.   protected:
  107.     // Responds to a change in size by calling Layout()
  108.     //
  109.     void            EvSize(uint sizeType, TSize& size);
  110.  
  111.     // Override TWindow virtual to allow cleanup of child metrics
  112.     //
  113.     void            RemoveChild(TWindow* child);
  114.  
  115.   protected_data:
  116.     TSize           ClientSize;
  117.  
  118.   private:
  119.     enum TWhichConstraint {
  120.       XConstraint,
  121.       YConstraint,
  122.       WidthConstraint,
  123.       HeightConstraint
  124.     };
  125.  
  126.     TChildMetrics*  ChildMetrics;
  127.     TConstraint*    Constraints;
  128.     TConstraint*    Plan;
  129.     TVariable*      Variables;
  130.     bool            PlanIsDirty;
  131.     int             NumChildMetrics;
  132.     int             FontHeight;
  133.  
  134.     TChildMetrics*  GetChildMetrics(TWindow& child);
  135.  
  136.     void            AddConstraint(TChildMetrics&     metrics,
  137.                                   TLayoutConstraint* c,
  138.                                   TWhichConstraint   whichContraint);
  139.     void            BuildConstraints(TChildMetrics& childMetrics);
  140.     void            RemoveConstraints(TChildMetrics& childMetrics);
  141.  
  142.     void            BuildPlan();
  143.     void            ExecutePlan();
  144.     void            ClearPlan();
  145.  
  146.     int             LayoutUnitsToPixels(int);
  147.     void            GetFontHeight();
  148.  
  149.     // Hidden to prevent accidental copying or assignment
  150.     //
  151.     TLayoutWindow(const TLayoutWindow&);
  152.     TLayoutWindow& operator =(const TLayoutWindow&);
  153.  
  154.   DECLARE_RESPONSE_TABLE(TLayoutWindow);
  155.   DECLARE_CASTABLE;
  156. };
  157.  
  158. // Generic definitions/compiler options (eg. alignment) following the 
  159. // definition of classes
  160. #include <services/posclass.h>
  161.  
  162. #if defined(BI_NAMESPACE)
  163. } // namespace OWL
  164. #endif
  165.  
  166. #endif  // OWL_LAYOUTWIN_H
  167.